﻿/*
* JavaScript库 V1.0
*/

(function() {
    window['PublicJS'] = {}                      // 注册命名空间

    /*
    功能: 获取对象
    id:   对象名称
    */
    function $O(id) {
        return document.getElementById(id);
    }
    window['PublicJS']['$O'] = $O;               // 注册方法到命名空间下

    /*
    功能: 获取对象value值
    id:   对象名称
    */
    function $V(id) {
        if (document.getElementById(id) == null)
            return "";
        else
            return document.getElementById(id).value;
    }
    window['PublicJS']['$V'] = $V;

    /*
    功能: 获取地址栏参数
    name: 参数名
    return: 返回参数值
    */
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);

        return "";
    }
    window['PublicJS']['GetQueryString'] = GetQueryString;

    /*
    功能: 获取select中的当前选中值
    selectName: select名称     
    */
    function GetSelectValue(selectName) {
        var objSelect = document.getElementById(selectName);
        return objSelect.value
    }
    window['PublicJS']['GetSelectValue'] = GetSelectValue;

    /*
    功能: 获取select中的当前选中text值
    selectName: select名称     
    */
    function GetSelectText(selectName) {
        var objSelect = document.getElementById(selectName);
        return objSelect.options[objSelect.selectedIndex].text;
    }
    window['PublicJS']['GetSelectText'] = GetSelectText;

    /*
    功能: 添加一条数据到listbox中
    control: 控件对象( var control = document.getElementById('name'); )
    objValue: 要添加的值
    */
    function ListBoxAdd(control, objValue, objText) {
        var node = document.createElement("OPTION");
        control.options.add(node);
        node.text = objText;
        node.value = objValue;

        control.appendChild(node);
    }
    window['PublicJS']['ListBoxAdd'] = ListBoxAdd;

    /*
    功能: 检索listbox中是否有该数据
    controlName: 控件名称
    objValue: 要检索的值
    返回 true 为存在，false 为不存在
    */
    function ListBoxSearch(controlName, objValue) {
        var obj = document.getElementById(controlName);
        var length = obj.length;

        for (var i = 0; i < length; i++) {
            var value = obj.options[i].value;
            var text = obj.options[i].text;

            if (text == objValue) return true;
        }

        return false;
    }
    window['PublicJS']['ListBoxSearch'] = ListBoxSearch;

    /*
    功能: 将listboxA中的单条数据转移到listboxB中
    lsbSource: listboxA
    ltbDestination: listboxB    
    */
    function ListBoxAddOne(lsbSource, ltbDestination) {
        var lst1 = window.document.getElementById(lsbSource);
        var lstindex = lst1.selectedIndex;
        if (lstindex < 0)
            return;
        var v = lst1.options[lstindex].value;
        var t = lst1.options[lstindex].text;
        var lst2 = window.document.getElementById(ltbDestination);
        var length = lst2.options.length;
        lst2.options[length] = new Option(t, v, true, true);
        lst1.options[lstindex].parentNode.removeChild(lst1.options[lstindex]);
    }
    window['PublicJS']['ListBoxAddOne'] = ListBoxAddOne;

    /*
    功能: 将listboxA中的所有数据转移到listboxB中
    lsbSource: listboxA
    ltbDestination: listboxB    
    */
    function ListBoxAddAll(lsbSource, ltbDestination) {
        var lst1 = window.document.getElementById(lsbSource);
        var length = lst1.options.length;
        if (length <= 0)
            return;
        var opNum = 0;
        var lst2 = window.document.getElementById(ltbDestination);
        for (var i = length; i > 0; i--) {
            var v = lst1.options[i - 1].value;
            var t = lst1.options[i - 1].text;
            lst2.options[opNum] = new Option(t, v, true, true);
            lst1.options[i - 1].parentNode.removeChild(lst1.options[i - 1]);
            opNum++;
        }
    }
    window['PublicJS']['ListBoxAddAll'] = ListBoxAddAll;

    /*
    功能: 将listName中的数据上移
    listName: 控件名称
    */
    function ListBoxUp(listName) {
        var obj = document.getElementById(listName);

        for (var i = 1; i < obj.length; i++) {
            //最上面的一个不需要移动，所以直接从i=1开始  .　　　　　　　　
            if (obj.options[i].selected) {
                if (!obj.options.item(i - 1).selected) {
                    var selText = obj.options[i].text;
                    var selValue = obj.options[i].value;
                    obj.options[i].text = obj.options[i - 1].text;
                    obj.options[i].value = obj.options[i - 1].value;
                    obj.options[i].selected = false;
                    obj.options[i - 1].text = selText;
                    obj.options[i - 1].value = selValue;
                    obj.options[i - 1].selected = true;
                }
            }
        }
    }
    window['PublicJS']['ListBoxUp'] = ListBoxUp;

    /*
    功能: 将listName中的数据下移
    listName: 控件名称
    */
    function ListBoxDown(listName) {
        var obj = document.getElementById(listName);

        for (var i = obj.length - 2; i >= 0; i--) {
            //向下移动，最后一个不需要处理，所以直接从倒数第二个开始  
            if (obj.options[i].selected) {
                if (!obj.options[i + 1].selected) {
                    var selText = obj.options[i].text;
                    var selValue = obj.options[i].value;
                    obj.options[i].text = obj.options[i + 1].text;
                    obj.options[i].value = obj.options[i + 1].value;
                    obj.options[i].selected = false;
                    obj.options[i + 1].text = selText;
                    obj.options[i + 1].value = selValue;
                    obj.options[i + 1].selected = true;
                }
            }
        }
    }
    window['PublicJS']['ListBoxDown'] = ListBoxDown;

    /*
    功能: 获取文件名带有扩展名 
    obj: file元素对象
    返回文件名如(01.jpg)
    */
    function getFileName(obj) {
        if (obj.value == "") return "";

        obj.value.replace("\\", "\\\\");
        var pos = obj.value.lastIndexOf("\\") * 1;
        return obj.value.substring(pos + 1);
    }
    window['PublicJS']['getFileName'] = getFileName;

    /*
    功能: 获取文件扩展名 
    obj: file元素对象
    返回文件扩展名如(jpg)
    */
    function getFileExt(obj) {
        var index = obj.value.lastIndexOf(".");
        var end = obj.value.length;

        return obj.value.substring(index, end);
    }
    window['PublicJS']['getFileExt'] = getFileExt;

    /*
    功能: 获取url地址扩展名 
    obj: file元素对象
    返回文件扩展名如(jpg)
    */
    function getUrlExt(url) {
        var index = url.lastIndexOf(".");
        var end = url.length;

        return url.substring(index + 1, end);
    }
    window['PublicJS']['getUrlExt'] = getUrlExt;

    /*
    功能: 匹配文件扩展名 
    strRegex: 用于验证图片扩展名的正则表达式(如: "(.jpg|.JPG|.gif|.GIF)$")
    fileName: 要匹配的文件名
    返回 true 为格式匹配，false 为格式不匹配
    */
    function checkFileType(strRegex, fileName) {
        var reg = new RegExp(strRegex);

        if (reg.test(fileName)) {
            return true;
        } else {
            return false;
        }
    }
    window['PublicJS']['checkFileType'] = checkFileType;

    /*
    功能: 向Select里添加Option
    obj: select对象
    sName: option的text值
    sValue: option的value值
    */
    function selectAddOption(obj, sName, sValue) {
        var oOption = document.createElement("option");
        oOption.appendChild(document.createTextNode(sName));

        if (arguments.length == 3) {
            oOption.setAttribute("value", sValue);
        }

        obj.appendChild(oOption);
    }
    window['PublicJS']['selectAddOption'] = selectAddOption;

    /*
    功能: 操作控件中的内容
    type: 0 减数据 1 加数据
    controlName: 控件名称
    objValue: 要操作的值
    */
    function addOrCutData(type, controlName, objValue) {
        if (type == 0) {
            var str = document.getElementById(controlName).value;
            str = str.replace(objValue + "|", "")
            document.getElementById(controlName).value = str;
        }
        else if (type == 1) {
            document.getElementById(controlName).value = document.getElementById(controlName).value + objValue + "|";
        }
    }
    window['PublicJS']['addOrCutData'] = addOrCutData;

    /*
    功能: 操作控件中的内容
    type: 0 减数据 1 加数据
    controlName: 控件名称
    objValue: 要操作的值
    schar: 用什么符号分隔 (如 , | $ ...)
    */
    function addOrCutDataByChar(type, controlName, objValue, schar) {
        if (type == 0) {
            var str = document.getElementById(controlName).value;
            str = str.replace(objValue + schar, "")
            document.getElementById(controlName).value = str;
        }
        else if (type == 1) {
            document.getElementById(controlName).value = document.getElementById(controlName).value + objValue + schar;
        }
    }
    window['PublicJS']['addOrCutDataByChar'] = addOrCutDataByChar;
    /*
    功能: 数据列表进行分页
    currentpage: 当前页
    pageall: 总页数
    fclick: 查询数据的方法名
    */
    function showPage(currentpage, pageall, fclick) {
        currentpage = parseInt(currentpage);
        pageall = parseInt(pageall);
        var begin, end;
        if (currentpage - 3 < 1) {
            begin = 1;
            end = (7 > pageall ? pageall : 7);
        }
        else {
            if (currentpage + 3 < pageall) {
                begin = currentpage - 3;
                end = currentpage + 3;
            }
            else {
                begin = (pageall - 7 > 1 ? pageall - 7 : 1);
                end = pageall;
            }
        }

        if (fclick == null) fclick = "showList";

        var pagehtml = '';
        if (currentpage > 1) pagehtml = '<span style="cursor:pointer;" onclick="' + fclick + '(' + (currentpage - 1) + ');"><a href="javascript:void(0)">上一页</a></span>';
        if (begin > 1) pagehtml += ' <a  href="javascript:void(0)" onclick="' + fclick + '(1);">' + 1 + '</a> ';
        if (begin > 2) pagehtml += '...';
        for (var i = begin; i <= end; i++) {
            if (i == currentpage) pagehtml += ' <b>' + i + '</b> ';
            else pagehtml += ' <a href="javascript:void(0)" onclick="' + fclick + '(' + i + ');">' + i + '</a> ';
        }
        if (pageall - end > 2) pagehtml += '...';
        if (pageall - end > 0) pagehtml += ' <a  href="javascript:void(0)" onclick="' + fclick + '(' + pageall + ');">' + pageall + '</a> ';
        if (currentpage < pageall) pagehtml += '<span style="cursor:pointer;" onclick="' + fclick + '(' + (currentpage + 1) + ');"><a href="javascript:void(0)">下一页</a></span>';
        if (currentpage < pageall) pagehtml += "&nbsp;<input id=\"iGo\" name=\"iGo\" type=\"text\" style=\"width:20px;\"/><a href=\"javascript:PublicJS.goToPage('" + fclick + "');\">GO</a>";

        return pagehtml;
    }
    window['PublicJS']['showPage'] = showPage;

    /*
    功能: 数据列表进行分页
    currentpage: 当前页
    pageall: 总页数
    fclick: 查询数据的方法名
    */
    function showPage2(currentpage, pageall, fclick) {
        currentpage = parseInt(currentpage);
        pageall = parseInt(pageall);
        var begin, end;
        if (currentpage - 3 < 1) {
            begin = 1;
            end = (7 > pageall ? pageall : 7);
        }
        else {
            if (currentpage + 3 < pageall) {
                begin = currentpage - 3;
                end = currentpage + 3;
            }
            else {
                begin = (pageall - 7 > 1 ? pageall - 7 : 1);
                end = pageall;
            }
        }

        if (fclick == null) fclick = "showList";

        var pagehtml = '';
        if (currentpage > 1) pagehtml = '<span style="cursor:pointer;" onclick="' + fclick + '(' + (currentpage - 1) + ');"><a style="cursor: pointer;">上一页</a></span>';
        if (begin > 1) pagehtml += ' <a style="cursor: pointer;"  onclick="' + fclick + '(1);">' + 1 + '</a> ';
        if (begin > 2) pagehtml += '...';
        for (var i = begin; i <= end; i++) {
            if (i == currentpage) pagehtml += '<a><b>' + i + '</b></a> ';
            else pagehtml += ' <a  style="cursor: pointer;" onclick="' + fclick + '(' + i + ');">' + i + '</a> ';
        }
        if (pageall - end > 2) pagehtml += '...';
        if (pageall - end > 0) pagehtml += ' <a  style="cursor: pointer;" onclick="' + fclick + '(' + pageall + ');">' + pageall + '</a> ';
        if (currentpage < pageall) pagehtml += '<span style="cursor:pointer;" onclick="' + fclick + '(' + (currentpage + 1) + ');"><a style="cursor: pointer;">下一页</a></span>';
        if (currentpage < pageall) pagehtml += "&nbsp;<a><input id=\"iGo\" name=\"iGo\" type=\"text\" style=\"width:40px;\"/></a><a href=\"javascript:PublicJS.goToPage('" + fclick + "');\">GO</a>";

        return pagehtml;
    }
    window['PublicJS']['showPage2'] = showPage2;

    /*
    功能: 数据列表进行分页
    currentpage: 当前页
    pageall: 总页数
    fclick: 查询数据的方法名
    bottomTip：底部显示出的文字
    */
    function showPage3(currentpage, pageall, fclick, bottomTip) {
        currentpage = parseInt(currentpage);
        pageall = parseInt(pageall);
        var begin, end;
        if (currentpage - 3 < 1) {
            begin = 1;
            end = (7 > pageall ? pageall : 7);
        }
        else {
            if (currentpage + 3 < pageall) {
                begin = currentpage - 3;
                end = currentpage + 3;
            }
            else {
                begin = (pageall - 7 > 1 ? pageall - 7 : 1);
                end = pageall;
            }
        }

        if (fclick == null) fclick = "showList";

        var pagehtml = "";

        if (bottomTip != "")
            pagehtml += '<span>' + bottomTip + '</span>&nbsp;&nbsp;';

        if (currentpage > 1) pagehtml += '<span style="cursor:pointer;" onclick="' + fclick + '(' + (currentpage - 1) + ');"><a href="javascript:void(0)">上一页</a></span>';
        if (begin > 1) pagehtml += ' <a  href="javascript:void(0)" onclick="' + fclick + '(1);">' + 1 + '</a> ';
        if (begin > 2) pagehtml += '...';
        for (var i = begin; i <= end; i++) {
            if (i == currentpage) pagehtml += ' <b>' + i + '</b> ';
            else pagehtml += ' <a href="javascript:void(0)" onclick="' + fclick + '(' + i + ');">' + i + '</a> ';
        }
        if (pageall - end > 2) pagehtml += '...';
        if (pageall - end > 0) pagehtml += ' <a  href="javascript:void(0)" onclick="' + fclick + '(' + pageall + ');">' + pageall + '</a> ';
        if (currentpage < pageall) pagehtml += '<span style="cursor:pointer;" onclick="' + fclick + '(' + (currentpage + 1) + ');"><a href="javascript:void(0)">下一页</a></span>';
        if (currentpage < pageall) pagehtml += "&nbsp;<input id=\"iGo\" name=\"iGo\" type=\"text\" style=\"width:20px;\"/><a href=\"javascript:PublicJS.goToPage('" + fclick + "');\">GO</a>";

        return pagehtml;
    }
    window['PublicJS']['showPage3'] = showPage3;

    /*
    功能:分页跳转  
    fclick: 查询数据的方法名  
    */
    function goToPage(fclick) {
        var currentpage = document.getElementById("iGo").value;

        currentpage = parseInt(currentpage);

        if (currentpage <= 0)
            currentpage == 1;

        var str = fclick + "(currentpage);";

        eval(str);
    }
    window['PublicJS']['goToPage'] = goToPage;

    /*
    功能:单选某列 
    注意：页面必须添加一控件<input id="hID" runat="server" name="hID" type="hidden" /> 
    */
    function cbSelect(obj, objvalue) {
        if (obj.checked) {
            PublicJS.addOrCutData(1, "hID", objvalue);

        }
        else {
            PublicJS.addOrCutData(0, "hID", objvalue);
        }
    }
    window['PublicJS']['cbSelect'] = cbSelect;

    /*
    功能:全选  
    注意：页面必须添加一控件<input id="hID" runat="server" name="hID" type="hidden" />     
    */
    function cbSelectAll() {
        document.getElementById("hID").value = "";

        var cbAll = document.getElementById("checkboxAll");
        var checkList = document.getElementsByTagName("input");

        if (cbAll.checked) {
            for (var i = 0; i < checkList.length; i++) {
                if (checkList[i].type == "checkbox" && checkList[i].id > 0) {
                    checkList[i].checked = true;
                    if (parseInt(checkList[i].id) > 0) PublicJS.addOrCutData(1, "hID", checkList[i].id);
                }
            }
        }
        else {
            for (var i = 0; i < checkList.length; i++) {
                if (checkList[i].type == "checkbox" && checkList[i].id > 0) {
                    checkList[i].checked = false;
                    if (parseInt(checkList[i].id) > 0) PublicJS.addOrCutData(0, "hID", checkList[i].id);
                }
            }
        }
    }
    window['PublicJS']['cbSelectAll'] = cbSelectAll;

    /*
    功能：选中某行,支持多选
    */
    function selectedTr(id) {
        $("tr").removeClass("selected");
        $("#tr_" + id).addClass("selected");
    }
    window['PublicJS']['selectedTr'] = selectedTr;

    /*
    功能：选中某行，背景色变化，不支持多选
    index: 定义的checkbox序号
    objvalue:选中行的ID号(数据库ID)
    注意:第一列必须定义为<input type='checkbox' name='ckbSelect' id='ckbSelect_" + i + "' onclick=\"PublicJS.ckbChecked(" + i + ")\" />
    */
    function ckbChecked(index, objvalue) {
        $("tr").removeClass("selected");
        $("#tr_" + index).addClass("selected");

        var obj = $("input[name='ckbSelect']");
        for (i = 0; i < obj.length; i++) {
            if (i != index) {
                obj[i].checked = false;
            }
            else {
                obj[i].checked = true;
                document.getElementById("hID").value = objvalue; // 添加ID到控件中
            }
        }
    }
    window['PublicJS']['ckbChecked'] = ckbChecked;

    /*
    功能: 将特殊字符转换为 字符串
    str: 需要转换的字符
    return: 返回转换后的字符串
    */
    function codeToStr(str) {
        var s = "";
        if (str.length == 0) return "";
        for (var i = 0; i < str.length; i++) {
            switch (str.substr(i, 1)) {
                case "<":
                    s += "&lt;";
                    break;
                case ">":
                    s += "&gt;";
                    break;
                case "&":
                    s += "&amp;";
                    break;
                case "   ":
                    s += "&nbsp;";
                    break;
                case "\"":
                    s += "&quot;";
                    break;
                case "\n":
                    s += "<br>";
                    break;
                default:
                    s += str.substr(i, 1);
                    break;
            }
        }
        return s;
    }
    window['PublicJS']['codeToStr'] = codeToStr;

    /*
    功能: 将字符串转换为 特殊字符 
    str: 需要转换的字符
    return: 返回转换后的字符串
    */
    function strToCode(str) {
        var s = "";
        if (str.length == 0) return "";

        s = str.replace(/&lt;/g, "<");
        s = s.replace(/&gt;/g, ">");
        s = s.replace(/&amp;/g, "&");
        s = s.replace(/&nbsp;/g, " ");
        s = s.replace(/&quot;/g, "\"");
        s = s.replace(/&<br>;/g, "\n");
        s = s.replace(/\/\/\//g, "\r\n");

        return s;
    }
    window['PublicJS']['strToCode'] = strToCode;

    /*
    功能: 获取本地文件大小(适用于IE6)
    fileName: 本地文件路径,即file控件中的value值
    return: 返回文件大小
    */
    function getFileSizeByIE6() {
        var file = new Image(); //把附件当做图片处理放在缓冲区预加载   
        file.dynsrc = document.getElementById("fudPolicy").value; //设置附件的url    
        var filesize = file.fileSize; //获取上传的文件的大小

        return filesize;
    }
    window['PublicJS']['getFileSizeByIE6'] = getFileSizeByIE6;

    /*
    功能: 获取本地文件大小(适用于IE7)
    fileName: 本地文件路径,即file控件中的value值
    return: 返回文件大小
    */
    function getFileSizeByIE7(fileName) {
        if (document.layers) {
            if (navigator.javaEnabled()) {
                var file = new java.io.File(fileName);
                if (location.protocol.toLowerCase() != 'file:') netscape.security.PrivilegeManager.enablePrivilege('UniversalFileRead');
                return file.length();
            }
            else return -1;
        }
        else if (document.all) {
            window.oldOnError = window.onerror;
            window.onerror = function(err) {
                if (err.indexOf('utomation') != -1) {
                    alert('file access not possible'); // 文件无法访问
                    return true;
                }
                else return false;
            };
            var fso = new ActiveXObject('Scripting.FileSystemObject');
            var file = fso.GetFile(fileName);
            window.onerror = window.oldOnError;
            return file.Size;
        }
    }
    window['PublicJS']['getFileSizeByIE7'] = getFileSizeByIE7;

    /*
    功能: 获取本地图片分辩率(只适用于IE7)
    fileName: 本地文件路径,即file控件中的value值
    return: 返回文件大小
    */
    function checkImageDimensions(fileName) {
        var imgURL = 'file:///' + fileName;

        var img = new Image();
        img.OnInit = loadHandler;
        if (document.layers && location.protocol.toLowerCase() != 'file:' && navigator.javaEnabled()) netscape.security.PrivilegeManager.enablePrivilege('UniversalFileRead');
        img.src = imgURL;

        alert(this.width + 'x' + this.height);
    }
    window['PublicJS']['checkImageDimensions'] = checkImageDimensions;

    /*
    功能：等分一个字符串
    str：要拆分的字符串
    num：等分为几段
    */
    function splitAverage(str, num) {
        var length = str.length;   // 总长度
        var unit = length / num;     // 单位长度

        var arrayStr = new Array(num);

        for (var i = 0; i < num; i++) {
            var text = str.substring(i * unit, (i + 1) * unit);

            arrayStr[i] = text;
        }

        return arrayStr;
    }
    window['PublicJS']['splitAverage'] = splitAverage;

    /*
    功能：拆分一个字符串,多少个字符为一段
    str：要拆分的字符串
    len：取多长   
    */
    function substringStr(str, len) {
        var length = str.length;   // 总长度
        var num = parseInt(length / len); // 可分为几段        
        num = (length % len == 0) ? num : (num + 1);

        var arrayStr = new Array(num);

        for (var i = 0; i < num; i++) {
            var text = str.substring(i * len, (i + 1) * len);

            arrayStr[i] = text;
        }

        return arrayStr;
    }
    window['PublicJS']['substringStr'] = substringStr;


    // Function Name: isValidPositiveInteger
    // Function Description: 
    /*
    功能：判断输入是否是一个正整数
    str：要判断的字符串
    */
    function isValidPositiveInteger(str) {
        var result = str.match(/^\d+$/);
        if (result == null) return false;
        if (parseInt(str) > 0) return true;
        return false;
    }
    window['PublicJS']['isValidPositiveInteger'] = isValidPositiveInteger;

    /*
    功能：判断输入是否是一个float型
    str：要判断的字符串
    */
    function isValidPositiveFloat(str) {
        if (isValidPositiveInteger(str))
            return true;

        var result = str.match(/^[1-9]d*.d*|0.d*[1-9]d*$/);

        if (result == null) return false;
        if (result > 0) return true;
        return false;
    }
    window['PublicJS']['isValidPositiveFloat'] = isValidPositiveFloat;

    /*
    功能：检查输入框内是否为数字型数据 (调用方法onkeyup="PublicJS.checkNum(this))
    str：要判断的字符串
    */
    function checkNum(obj) {
        var sValue = obj.value;

        if (sValue != "") {
            if (!PublicJS.isValidPositiveFloat(sValue)) {
                obj.value = "";
                obj.focus();
                alert("非法输入,输入格式应该为小数(如xxxx.xx,120.4)！");
                return false;
            }
        }
    }
    window['PublicJS']['checkNum'] = checkNum;

    /*
    功能：将货币数字（阿拉伯数字）(小写)转化成中文(大写） 
    参数：Num为字符型,小数点之后保留两位,例：Arabia_to_Chinese("1234.06")
    说明：1.目前本转换仅支持到 拾亿（元） 位，金额单位为元，不能为万元，最小单位为分
    2.不支持负数
    */
    function numToChinese(Num) {
        for (i = Num.length - 1; i >= 0; i--) {
            Num = Num.replace(",", "")//替换tomoney()中的“,”
            Num = Num.replace(" ", "")//替换tomoney()中的空格
        }

        Num = Num.replace("￥", "")//替换掉可能出现的￥字符
        if (isNaN(Num)) {
            //验证输入的字符是否为数字
            alert("请检查小写金额是否正确");
            return;
        }
        //---字符处理完毕，开始转换，转换采用前后两部分分别转换---//
        part = String(Num).split(".");
        newchar = "";
        //小数点前进行转化
        for (i = part[0].length - 1; i >= 0; i--) {
            if (part[0].length > 10) { alert("位数过大，无法计算"); return ""; } //若数量超过拾亿单位，提示
            tmpnewchar = ""
            perchar = part[0].charAt(i);
            switch (perchar) {
                case "0": tmpnewchar = "零" + tmpnewchar; break;
                case "1": tmpnewchar = "壹" + tmpnewchar; break;
                case "2": tmpnewchar = "贰" + tmpnewchar; break;
                case "3": tmpnewchar = "叁" + tmpnewchar; break;
                case "4": tmpnewchar = "肆" + tmpnewchar; break;
                case "5": tmpnewchar = "伍" + tmpnewchar; break;
                case "6": tmpnewchar = "陆" + tmpnewchar; break;
                case "7": tmpnewchar = "柒" + tmpnewchar; break;
                case "8": tmpnewchar = "捌" + tmpnewchar; break;
                case "9": tmpnewchar = "玖" + tmpnewchar; break;
            }
            switch (part[0].length - i - 1) {
                case 0: tmpnewchar = tmpnewchar + "元"; break;
                case 1: if (perchar != 0) tmpnewchar = tmpnewchar + "拾"; break;
                case 2: if (perchar != 0) tmpnewchar = tmpnewchar + "佰"; break;
                case 3: if (perchar != 0) tmpnewchar = tmpnewchar + "仟"; break;
                case 4: tmpnewchar = tmpnewchar + "万"; break;
                case 5: if (perchar != 0) tmpnewchar = tmpnewchar + "拾"; break;
                case 6: if (perchar != 0) tmpnewchar = tmpnewchar + "佰"; break;
                case 7: if (perchar != 0) tmpnewchar = tmpnewchar + "仟"; break;
                case 8: tmpnewchar = tmpnewchar + "亿"; break;
                case 9: tmpnewchar = tmpnewchar + "拾"; break;
            }
            newchar = tmpnewchar + newchar;
        }
        //小数点之后进行转化
        if (Num.indexOf(".") != -1) {
            if (part[1].length > 2) {
                alert("小数点之后只能保留两位,系统将自动截段");
                part[1] = part[1].substr(0, 2)
            }
            for (i = 0; i < part[1].length; i++) {
                tmpnewchar = ""
                perchar = part[1].charAt(i)
                switch (perchar) {
                    case "0": tmpnewchar = "零" + tmpnewchar; break;
                    case "1": tmpnewchar = "壹" + tmpnewchar; break;
                    case "2": tmpnewchar = "贰" + tmpnewchar; break;
                    case "3": tmpnewchar = "叁" + tmpnewchar; break;
                    case "4": tmpnewchar = "肆" + tmpnewchar; break;
                    case "5": tmpnewchar = "伍" + tmpnewchar; break;
                    case "6": tmpnewchar = "陆" + tmpnewchar; break;
                    case "7": tmpnewchar = "柒" + tmpnewchar; break;
                    case "8": tmpnewchar = "捌" + tmpnewchar; break;
                    case "9": tmpnewchar = "玖" + tmpnewchar; break;
                }
                if (i == 0) tmpnewchar = tmpnewchar + "角";
                if (i == 1) tmpnewchar = tmpnewchar + "分";
                newchar = newchar + tmpnewchar;
            }
        }
        //替换所有无用汉字
        while (newchar.search("零零") != -1)
            newchar = newchar.replace("零零", "零");
        newchar = newchar.replace("零亿", "亿");
        newchar = newchar.replace("亿万", "亿");
        newchar = newchar.replace("零万", "万");
        newchar = newchar.replace("零元", "元");
        newchar = newchar.replace("零角", "");
        newchar = newchar.replace("零分", "");

        if (newchar.charAt(newchar.length - 1) == "元" || newchar.charAt(newchar.length - 1) == "角")
            newchar = newchar + "整"
        return newchar;
    }
    window['PublicJS']['numToChinese'] = numToChinese;


})();
